#!/bin/bash

np=4

no_proc=$(( ${np} * 4 ))
#headroom=$(( 400*1024*1024 ))
headroom=$(( 400*1024*64 ))
#mem=$(( ( (512*1024*1024)-${headroom}) / 8 ))
mem=$(( ( (512*1024*64)-${headroom}) / 8 ))
root_np=$(echo "sqrt(${no_proc})" | bc)

no_pix=$(echo "sqrt((${mem}/6))*${root_np}" | bc)
no_bin=4
no_gang=1
sblock_size=$(( ${no_pix} / ${root_np} ))
#fblock_size=$(( 4*1024*1024 ))
fblock_size=$(( 4*1024*64 ))
rmod=1
wmod=1

echo "no_proc    = ${no_proc}"
echo "headroom   = ${headroom}"
echo "mem        = ${mem}"
echo "no_pix     = ${no_pix}"
echo "no_bin     = ${no_bin}"
echo "no_gang    = ${no_gang}"
echo "sblocksize = ${sblock_size}"
echo "fblocksize = ${fblock_size}"
echo "wmod       = ${wmod}"
echo "rmod       = ${rmod}"

export IOMETHOD=MPI
#export REMAP= #SCALAPACK

mpiexec -f ./hosts -np $np ./MADbench2 $no_pix $no_bin $no_gang $sblock_size $fblock_size $rmod $wmod 
